﻿using System;
using System.Text.RegularExpressions;

namespace FileSquirrel.Logic
{
    public class FileNameHelper
    {
        private string _show;
        private string _season;
        private string _episode;

        public FileNameHelper(string FileName)
        {
            Regex regex1 = new Regex(@"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?");
            Regex regex2 = new Regex(@"(.*?)\s*-*\s*(\d+)x(\d+).*?");
            Regex regex3 = new Regex(@"(.*?)\s*-*\s*(\d*)(\d\d).*?");

            if (regex1.IsMatch(FileName))
            //Regex.IsMatch(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?"))
            {
                _show = regex1.Match(FileName).Groups[1].Value;
                //_show = Regex.Match(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?").Groups[1].Value;
                _season = regex1.Match(FileName).Groups[2].Value;
                //_season = Regex.Match(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?").Groups[2].Value;
                _episode = regex1.Match(FileName).Groups[3].Value;
                //_episode = Regex.Match(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?").Groups[3].Value;
            }
            //else if (Regex.IsMatch(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?"))
            else if (regex2.IsMatch(FileName))
            {
                //_show = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?").Groups[1].Value;
                _show = regex2.Match(FileName).Groups[1].Value;
                //_season = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?").Groups[2].Value;
                _season = regex2.Match(FileName).Groups[2].Value;
                //_episode = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?").Groups[3].Value;
                _episode = regex2.Match(FileName).Groups[3].Value;
            }
            //else if (Regex.IsMatch(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?"))
            else if (regex3.IsMatch(FileName))
            {
                _show = regex3.Match(FileName).Groups[1].Value;
                //_show = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?").Groups[1].Value;
                _season = regex3.Match(FileName).Groups[2].Value;
                //_season = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?").Groups[2].Value;
                _episode = regex3.Match(FileName).Groups[3].Value;
                //_episode = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?").Groups[3].Value;
            }
        }

        #region Property Procedures

        public string Show
        {
            get { return _show; }
            set { _show = value; }
        }

        public string Season
        {
            get
            {
                return
                    "Season " + (string.IsNullOrEmpty(_season) ? 0 : Convert.ToInt32(_season));
            }
            set { _season = value; }
        }

        public string Episode
        {
            get { return _episode; }
            set { _episode = value; }
        }

        #endregion Property Procedures
    }
}